﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_ManagerPages_updateStaff : System.Web.UI.Page
{
    int id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        id = Convert.ToInt32(Request.QueryString["id"].ToString());
        ManagerBUS m = new ManagerBUS();
        Staff s=new Staff();
        s.Id=id;
        DataSet ds = m.searchStaffById(s);
        txtFullName.Text = ds.Tables[0].Rows[0]["fullName"].ToString();
        txtUserName.Text = ds.Tables[0].Rows[0]["userName"].ToString();
        txtAddress.Text = ds.Tables[0].Rows[0]["address"].ToString();
        txtEmail.Text = ds.Tables[0].Rows[0]["email"].ToString();
        txtPhone.Text = ds.Tables[0].Rows[0]["phoneNo"].ToString();
        txtMajor.Text = ds.Tables[0].Rows[0]["major"].ToString();
    }
    protected void btnUpdateStaff_Click(object sender, EventArgs e)
    {
        ManagerBUS m = new ManagerBUS();
        Staff s1 = new Staff();
        s1.Id = id;
        DataSet ds = m.searchStaffById(s1);
        Staff st = new Staff();
        st.Password = ds.Tables[0].Rows[0]["pass"].ToString();
        st.Id = id;
        st.Address = txtAddress.Text;
        st.Email = txtEmail.Text;
        st.Fullname = txtFullName.Text;
        st.Major = txtMajor.Text;
        st.PhoneNumber = txtPhone.Text;
        st.Username = txtUserName.Text;
        if (m.updateStaff(st))
        {
            Response.Redirect("~/Pages/HomePage/Success.aspx");
        }
        else
        {
            lblWarningUpdateStaff.Text = "Failed";
        }
    }
}